#include "stdafx.h"
#include "PackIn.h"

CPackIn::CPackIn()
{
}

CPackIn::~CPackIn()
{
}

bool CPackIn::AddByte(byte cByte)
{
	m_strBuffer.Append((char*)&cByte, sizeof(byte));
	return true;
}

bool CPackIn::AddInt(int nInt)
{
	nInt = htonl(nInt);
	m_strBuffer.Append((char*)&nInt, sizeof(int));
	return true;
}

bool CPackIn::AddDWord(DWORD dwDWrod)
{
	dwDWrod = htonl(dwDWrod);
	m_strBuffer.Append((char*)&dwDWrod, sizeof(DWORD));
	return true;
}

bool CPackIn::AddString(CString strString)
{
	int nLen = strString.GetLength() * sizeof(TCHAR) + sizeof(TCHAR);
	AddInt(nLen);
	m_strBuffer.Append((char*)strString.GetBuffer(), nLen);
	return true;
}

bool CPackIn::AddString(CStringA strString)
{
	int nLen = strString.GetLength() + sizeof(char);
	AddInt(nLen);
	m_strBuffer.Append((char*)strString.GetBuffer(), nLen);
	return true;
}

bool CPackIn::ResetBuffer()
{
	m_strBuffer.Empty();
	return true;
}

CBuffer CPackIn::GetBuffer()
{
	return m_strBuffer;
}

bool CPackIn::AddWord(WORD wWord)
{
	wWord = htons(wWord);
	m_strBuffer.Append((char*)&wWord, sizeof(WORD));
	return true;
}

bool CPackIn::Append(char* pBuffer, int nLen)
{
	m_strBuffer.Append(pBuffer, nLen);
	return true;
}
